<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <link rel="stylesheet" href="../css/orderset.css">
        <!-- 引入组件库 -->
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
    </head>
    <body class="hold-transition">
    <div id="app">
        <div class="content-header">
            <h1>会员管理<small>会员档案</small></h1>
            <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>会员管理</el-breadcrumb-item>
                <el-breadcrumb-item>会员档案</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="app-container">
            <!--新增|修改弹层-->
            <div class="add-form">
                <el-dialog v-bind:title="title" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name" >
                                    <el-input v-model="formData.name"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="档案编码" prop="fileNumber">
                                    <el-input v-model="formData.fileNumber"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="不限" value="0"></el-option>
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="手机号码" prop="phoneNumber">
                                    <el-input v-model="formData.phoneNumber" type="text"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="身份证号" prop="idCard">
                                    <el-input v-model="formData.idCard" type="text"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="email" prop="email">
                                    <el-input v-model="formData.email" type="text"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="生日">
                                    <el-input v-model="formData.birthday" type="date"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="备注">
                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!--页面主要内容-->
            <div class="box">
                <div class="filter-container">
                    <el-input placeholder="姓名/手机号码" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                    <el-button @click="findPage()" class="dalfBut">查询</el-button>
                    <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                </div>
                <div class="clearfix"></div>
                <div class="app-container">
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="name" label="姓名" align="center" ></el-table-column>
                        <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                        <el-table-column label="适用性别" align="center">
                            <template slot-scope="scope">
                                <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="idCard" label="身份证号" align="center"></el-table-column>
                        <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                        <el-table-column prop="regTime" label="注册时间" align="center"></el-table-column>
                        <el-table-column prop="email" label="email" align="center"></el-table-column>
                        <el-table-column prop="birthday" label="生日" align="center"></el-table-column>
                        <el-table-column prop="remark" label="备注" align="center"></el-table-column>
                        <el-table-column label="操作" align="center" width="180">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
<!--                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>-->
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script>
        new Vue({
            el: '#app',
            data:{
                title:'',
                dialogFormVisible:false,
                selectdate:'',
                dataList:[],
                formData:{},
                pagination:{
                    currentPage:1,
                    pageSize:10,
                    queryString:'',
                    total:0
                },
                rules:{
                    name: [
                        { required: true, message: '请输入姓名', trigger: 'blur' },
                        { min: 2, max: 8, message: '长度在 2 到 8 个字符', trigger: 'blur' }
                    ],
                    fileNumber:[
                        { required: false, message: '请档案编号', trigger: 'blur' },
                    ],
                    phoneNumber:[
                        { required: true,pattern: /^0{0,1}(13[0-9]|15[7-9]|153|18[0-9]|199)[0-9]{8}$/, message: '手机号格式有误', trigger: 'blur' },
                    ],
                    idCard:[
                        { required:true,pattern: /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,message: '身份证格式有误', trigger: 'blur' }
                    ],
                    email:[
                        {required:true,pattern:/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/,message: '邮箱格式有误', trigger: 'blur' }
                    ]
                },
            },

            created: function () {//在vue初始化时调用
                this.initData(null);
            },
            methods: {
                //提交表单
                handleAdd(){
                    this.$refs['dataAddForm'].validate((valid)=>{
                        if(valid) {
                            if(this.formData.id===undefined){
                                axios.post("/member/add.do",this.formData).then((res)=>{
                                    this.getFlag(res);
                                })
                            }else {
                                axios.post("/member/edit.do",this.formData).then((res)=>{
                                    this.getFlag(res);
                                })
                            }
                        }
                    })
                },
                //打开新增弹层
                handleCreate(){
                    this.formData={};
                    this.dialogFormVisible=true;
                    this.title='新增会员';
                },
                //打开修改弹层
                handleUpdate(row){
                    this.formData={};
                    this.dialogFormVisible=true;
                    this.title='修改会员';
                    axios.get("/member/findById.do?id="+row.id).then((res)=>{
                        if (res.data.flag){
                            this.formData=res.data.data;
                        }else {
                            this.$message.error(res.data.message);
                        }
                    })
                },
                //分页查询
                findPage(){
                    this.pagination.currentPage=1;
                    this.initData(this.selectdate);
                },
                //翻页查询
                handleCurrentChange(currentPage){
                    this.pagination.currentPage=currentPage;
                    this.initData(this.selectdate);
                },
                //初始化当前页要展示的日期
                getFlag(res){
                    if(res.data.flag){
                        this.$message({
                            message:res.data.message,
                            type:'success'
                        })
                    }else {
                        this.$message.error(res.data.message);
                    }
                },
				initData(cur) {
                    if (cur) {
                        this.selectdate=cur;
                    } else {
                        var date = new Date();
                        this.selectdate = this.formatDate( date.getFullYear(), date.getMonth() + 1,date.getDate());
                    }

                    axios.post("/member/findByPage.do",this.pagination).then((res)=>{
                        this.dataList=res.data.rows;
                        this.pagination.total=res.data.total;
                    })
                },
                // 返回 类似 2016-01-02 格式的字符串
                formatDate: function (year, month, day) {
                    var y = year;
                    var m = month;
                    if (m < 10) m = "0" + m;
                    var d = day;
                    if (d < 10) d = "0" + d;
                    return y + "-" + m + "-" + d
                }
            }
        })
    </script>
</html>